<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>StoneBase 后台管理 - 登录</title>
    <meta name="keywords" content="StoneBase 后台管理">
    <meta name="description" content="StoneBase 后台管理">

    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/admin/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/admin/css/animate.min.css" rel="stylesheet">
    <link href="/static/admin/css/style.min.css" rel="stylesheet"><base target="_blank">
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen  animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name">BS</h1>

        </div>
        <h3>欢迎使用 StoneBase 后台管理</h3>
        <form class="m-t" role="form" id = "myform">
            <div class="form-group has-feedback">
                <input type="text" class="form-control" placeholder="手机号码" name="mobile" id="mobile" />
                <span class="form-control-feedback hidden" aria-hidden="true" ></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" placeholder="密码" name="password" id="password" />
                <span class="form-control-feedback hidden" aria-hidden="true" ></span>
            </div>
            <div class="form-group has-feedback" style="margin-bottom:70px">
                <input type="text" class="form-control" placeholder="验证码" style="color:black;width:170px;float:left;margin-right:2px;" name="code" id="code"/>
                <span class="form-control-feedback hidden" aria-hidden="true" ></span>
                <img id="codeimg" src="/admin/login/verify" onclick="javascript:this.src='/admin/login/verify?tm='+Math.random();" style="float:left;cursor: pointer"/>

            </div>
                <button class="btn btn-success btn-block" id="login_btn">登录</button>
        </form>

    </div>
</div>
<script src="/static/admin/js/jquery.min.js"></script>
<script src="/static/admin/js/bootstrap.min.js"></script>
<script src="/static/admin/js/plugins/layer/layer.js"></script>
<script src="/static/admin/js/plugins/validate/jquery.validate.js"></script>
<script src="/static/admin/js/plugins/validate/messages_zh.min.js"></script>
</body>
<script type="text/javascript">
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // enter 键
            $('#login_btn').click();
        }
    };

    $.validator.setDefaults( {
        submitHandler: function () {
            //加载层-风格3
            // layer.load(2);
            //此处演示关闭
            $('#login_btn').removeClass('btn-success').addClass('btn-danger').val('登陆中...');
            var mobile = $('#mobile').val();
            var password = $('#password').val();
            var code = $('#code').val();
            $.ajax({
                type: "post",//提交方式
                url: "/admin/login/doLogin",//提交地址
                data: {'mobile':mobile, 'password':password, 'code':code},//将表单全部提交
                async: true,//设置同步或者异步,false为同步
                dataType:"json",
                success: function(returnData) {//成功后返回数据data，并进行操作

                    if(returnData.code !=200){
                        $("#codeimg").attr('src','/admin/login/verify?tm='+Math.random());

                        layer.msg(returnData.msg.message);
                        layer.closeAll('loading');
                        $("#code").val('');
                        if (returnData.code ==4)$("#code").focus();
                        $('#login_btn').removeClass('btn-danger').addClass('btn-success').val('登陆');
                        return;
                    }else{

                        layer.msg(returnData.msg.message, {time : 1000});
                        window.location.href= returnData.msg.url;
                    }
                }
            });
        }
    } );

    $(document).ready( function () {
        $( "#myform" ).validate( {
            onfocusout : function(element) {
                $(element).valid();
            },
            onkeyup : false,
            focusInvalid : false,
            rules: {
                mobile: {
                    required: true,
                    digits:true,
                    maxlength:11,
                    minlength:11
                },

                password: {
                    required: true
                },

                code: {
                    required: true,
                    maxlength:4,
                    minlength:4
                }
            },
            errorElement: "em",
            errorPlacement: function ( error, element ) {
                $( element).next().removeClass().addClass("glyphicon glyphicon-remove form-control-feedback show");
            },
            highlight: function ( element, errorClass, validClass ) {
                $( element ).parents( ".has-feedback" ).removeClass("has-success").addClass( "has-error" );
                $( element).next().removeClass().addClass("glyphicon glyphicon-remove form-control-feedback show");

            },
            unhighlight: function (element, errorClass, validClass) {
                $( element ).parents( ".has-feedback" ).removeClass("has-error" ).addClass( "has-success" );
                $( element).next().removeClass().addClass("glyphicon glyphicon-ok show form-control-feedback show");

            }
        } );
    } );


    /*$(function () {
        $('#login_btn').click(function(){
            //加载层-风格3
            layer.load(2);
            //此处演示关闭
            $('#login_btn').removeClass('btn-success').addClass('btn-danger').val('登陆中...');
            var mobile = $('#mobile').val();
            var password = $('#password').val();
            var code = $('#code').val();
            $.ajax({
                type: "post",//提交方式
                url: "/admin/login/doLogin",//提交地址
                data: {'mobile':mobile, 'password':password, 'code':code},//将表单全部提交
                async: true,//设置同步或者异步,false为同步
                dataType:"json",
                success: function(returnData) {//成功后返回数据data，并进行操作
                    if(returnData.code !=0){
                        if (returnData.code == 4){ $("#codeimg").attr('src','/admin/login/verify?tm='+Math.random());}
                        layer.msg(returnData.msg);
                        layer.closeAll('loading');
                        $('#login_btn').removeClass('btn-danger').addClass('btn-success').val('登陆');
                        return;
                    }else{
                        layer.msg(returnData.msg);
                        window.location.href= returnData.data.url;
                    }
                }
            });
        });
    });*/
</script>
</html>
